package com.xxxx.server.exception;

import com.xxxx.server.util.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @Author:王亚栋
 * @Date: 2023/6/18 上午11:41
 * @Version:1.0
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SQLException.class)
    public RespBean sqlException(SQLException e){

        if (e instanceof SQLIntegrityConstraintViolationException){

            return RespBean.error("该数据有关联数据，操作异常!");
        }

        return RespBean.error("数据有异常，操作失败!");

    }


}
